package com.happy.unitconvert.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 应用配置属性
 */
@Component
@ConfigurationProperties(prefix = "app")
public class AppProperties {

  /**
   * 应用名称
   */
  private String name = "UnitConvert API";

  /**
   * 应用版本
   */
  private String version = "1.0.0";

  /**
   * 应用描述
   */
  private String description = "为Android、iOS、小程序等提供统一的单位转换API服务";

  /**
   * 是否启用调试模式
   */
  private boolean debug = false;

  /**
   * API配置
   */
  private Api api = new Api();

  /**
   * 转换配置
   */
  private Conversion conversion = new Conversion();

  /**
   * 汇率配置
   */
  private ExchangeRate exchangeRate = new ExchangeRate();

  public static class Api {
    /**
     * API版本
     */
    private String version = "v1";

    /**
     * API基础路径
     */
    private String basePath = "/api/v1";

    /**
     * 请求限流配置
     */
    private RateLimit rateLimit = new RateLimit();

    public static class RateLimit {
      /**
       * 是否启用限流
       */
      private boolean enabled = true;

      /**
       * 每分钟最大请求数
       */
      private int maxRequestsPerMinute = 1000;

      // Getters and Setters
      public boolean isEnabled() {
        return enabled;
      }

      public void setEnabled(boolean enabled) {
        this.enabled = enabled;
      }

      public int getMaxRequestsPerMinute() {
        return maxRequestsPerMinute;
      }

      public void setMaxRequestsPerMinute(int maxRequestsPerMinute) {
        this.maxRequestsPerMinute = maxRequestsPerMinute;
      }
    }

    // Getters and Setters
    public String getVersion() {
      return version;
    }

    public void setVersion(String version) {
      this.version = version;
    }

    public String getBasePath() {
      return basePath;
    }

    public void setBasePath(String basePath) {
      this.basePath = basePath;
    }

    public RateLimit getRateLimit() {
      return rateLimit;
    }

    public void setRateLimit(RateLimit rateLimit) {
      this.rateLimit = rateLimit;
    }
  }

  public static class Conversion {
    /**
     * 默认精度（小数位数）
     */
    private int defaultPrecision = 10;

    /**
     * 最大精度
     */
    private int maxPrecision = 15;

    /**
     * 是否启用缓存
     */
    private boolean cacheEnabled = true;

    /**
     * 缓存过期时间（秒）
     */
    private long cacheExpireSeconds = 3600;

    // Getters and Setters
    public int getDefaultPrecision() {
      return defaultPrecision;
    }

    public void setDefaultPrecision(int defaultPrecision) {
      this.defaultPrecision = defaultPrecision;
    }

    public int getMaxPrecision() {
      return maxPrecision;
    }

    public void setMaxPrecision(int maxPrecision) {
      this.maxPrecision = maxPrecision;
    }

    public boolean isCacheEnabled() {
      return cacheEnabled;
    }

    public void setCacheEnabled(boolean cacheEnabled) {
      this.cacheEnabled = cacheEnabled;
    }

    public long getCacheExpireSeconds() {
      return cacheExpireSeconds;
    }

    public void setCacheExpireSeconds(long cacheExpireSeconds) {
      this.cacheExpireSeconds = cacheExpireSeconds;
    }
  }

  public static class ExchangeRate {
    /**
     * 汇率API基础URL
     */
    private String baseUrl = "https://api.exchangerate-api.com/v4";

    /**
     * API密钥（可选，免费API通常不需要）
     */
    private String apiKey;

    /**
     * 是否启用缓存
     */
    private boolean cacheEnabled = true;

    /**
     * 缓存时间（分钟）
     */
    private int cacheMinutes = 30;

    /**
     * 请求超时时间（秒）
     */
    private int timeoutSeconds = 30;

    /**
     * 重试次数
     */
    private int retryCount = 3;

    /**
     * 默认基础货币
     */
    private String defaultBaseCurrency = "USD";

    // Getters and Setters
    public String getBaseUrl() {
      return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
      this.baseUrl = baseUrl;
    }

    public String getApiKey() {
      return apiKey;
    }

    public void setApiKey(String apiKey) {
      this.apiKey = apiKey;
    }

    public boolean isCacheEnabled() {
      return cacheEnabled;
    }

    public void setCacheEnabled(boolean cacheEnabled) {
      this.cacheEnabled = cacheEnabled;
    }

    public int getCacheMinutes() {
      return cacheMinutes;
    }

    public void setCacheMinutes(int cacheMinutes) {
      this.cacheMinutes = cacheMinutes;
    }

    public int getTimeoutSeconds() {
      return timeoutSeconds;
    }

    public void setTimeoutSeconds(int timeoutSeconds) {
      this.timeoutSeconds = timeoutSeconds;
    }

    public int getRetryCount() {
      return retryCount;
    }

    public void setRetryCount(int retryCount) {
      this.retryCount = retryCount;
    }

    public String getDefaultBaseCurrency() {
      return defaultBaseCurrency;
    }

    public void setDefaultBaseCurrency(String defaultBaseCurrency) {
      this.defaultBaseCurrency = defaultBaseCurrency;
    }
  }

  // Getters and Setters
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getVersion() {
    return version;
  }

  public void setVersion(String version) {
    this.version = version;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public boolean isDebug() {
    return debug;
  }

  public void setDebug(boolean debug) {
    this.debug = debug;
  }

  public Api getApi() {
    return api;
  }

  public void setApi(Api api) {
    this.api = api;
  }

  public Conversion getConversion() {
    return conversion;
  }

  public void setConversion(Conversion conversion) {
    this.conversion = conversion;
  }

  public ExchangeRate getExchangeRate() {
    return exchangeRate;
  }

  public void setExchangeRate(ExchangeRate exchangeRate) {
    this.exchangeRate = exchangeRate;
  }
}
